<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //说明：将子类的原型挂载到父类上；
        // 缺点：子类new出来的实例，父类的属性没有隔离，会相互影响；
        function Parent2() {
            this.name = 'parent2'
            this.arr = [1, 2, 3]
        }
        Parent2.prototype.say = function () {
            console.log(this.name)
        }
        function Child2() {
            this.type = 'child2'
        }
        Child2.prototype = new Parent2() //原型继承核心代码
        let child2_1 = new Child2()
        let child2_2 = new Child2()

        console.log(child2_1.name) // parent2
        console.log(child2_1.say()) // parent2
        child2_1.arr.push(4)
        console.log(child2_1.arr, child2_2.arr) // [1, 2, 3, 4]  [1, 2, 3, 4]

    </script>
</body>

</html>